package com.matrix.java.chap_06;

import java.util.Scanner;

/*
    计算一个字符串中字母的个数
 */
public class Ex6_20 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        System.out.print("输入: ");
        String str = input.next();
        input.close();
        System.out.println("个数: " + countLetters(str));
    }

    private static int countLetters(String s) {
        int countLetters = 0;
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            if ((ch > 64 && ch < 91) || (ch > 96 && ch < 123)) {
                countLetters++;
            }
        }
        return countLetters;
    }
}
